#!/usr/bin/env bash
echo '==================1.开发环境准备================================'
echo '1.1请确保安装并java8, git, maven并设置好环境变量'
echo '1.2请确保安装并docker,docker-compose并设置好环境变量'

#确认环境信息准备就绪
#read -r -p "开发环境准备好了吗? [Y/n] " envConfirm
#case $envConfirm in
#    [yY][eE][sS]|[yY])
#		echo "Yes 继续执行"
#		;;
#    [nN][oO]|[nN])
#		echo "No 终止执行"
#		exit 1
#       	;;
#    *)
#		echo "Invalid input... 终止执行"
#		exit 1
#		;;
#esac

echo '==================1.3清理当前脚本启动的容器和产生的镜像(可选的)=============='
#清理当前脚本启动的容器和产生的镜像(可选的)
docker stop sc-rabbitmq sc-redis sc-mysql
docker rm sc-rabbitmq sc-redis sc-mysql
docker image rm rabbitmq:alpine redis:alpine mysql:9.6-alpine

#docker stop sc-monitor-admin sc-authorization-server sc-authentication-server sc-organization sc-gateway-admin sc-gateway-web
#docker rm sc-monitor-admin sc-authorization-server sc-authentication-server sc-organization sc-gateway-admin sc-gateway-web
#docker image rm cike/admin cike/authorization-server:latest cike/authentication-server:latest cike/organization:latest cike/gateway-admin:latest cike/gateway-web:latest

#docker stop sc-producer sc-consumer-feign sc-consumer-ribbon sc-consumer-admin
#docker rm sc-producer sc-consumer-feign sc-consumer-ribbon sc-consumer-admin
#docker image rm cike/producer:latest cike/consumer-feign:latest cike/consumer-ribbon:latest cike/consumer-admin:latest

#echo '==================2.安装认证公共包到本地maven仓库=================='
#安装认证公共包到本地maven仓库
#cd common && mvn install
#echo '当前目录:' && pwd

#回到根目录
#cd -

#echo '==================3.安装认证客户端到本地maven仓库=================='
#安装认证客户端到本地maven仓库
#cd auth/authentication-client && mvn install -Dmaven.test.skip=true
#echo '当前目录:' && pwd

#回到根目录
cd -

echo '==================4.docker-compose启动公共服务==================='
#去docker-compose目录
cd docker-compose
echo '==================4.1显示环境变量: docker-compose/.env =========='
#显示环境变量
cat ./.env
echo ''

#按需要开启公共服务
echo '==================4.2启动 mysql or redis or rabbitmq ========'
#docker-compose -f docker-compose.yml up -d mysql
docker-compose -f docker-compose.yml up -d redis
docker-compose -f docker-compose.yml up -d rabbitmq


#回到根目录
cd -

echo '==================4.3.构建镜像: 配置中心, 消息中心========'

#回到根目录
cd -
echo '当前目录:' && pwd
cd ..
#构建镜像:消息中心
cd ./center/bus
mvn package -Dmaven.test.skip=true && mvn docker:build

#回到根目录
cd -

echo '==================4.4.启动注册中心, 配置中心, 消息中心============'
#去docker-compose目录
cd docker-compose

#启动注册中心
docker-compose -f docker-compose.yml -f docker-compose.nacos.yml up -d nacos

#启动消息中心
docker-compose -f docker-compose.yml -f docker-compose.center.yml up -d bus-server
